package org.tapaha.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class DateCalculator {
	 public static String getDate(String type) {
		Date dt = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat(type); 
		
		return sdf.format(dt).toString();
	}
	public static String getYesterdayDate(String date) {
		Calendar cal = new GregorianCalendar();
		String arr[] = date.split("-");
		
		cal.set(Integer.parseInt(arr[0]), Integer.parseInt(arr[1]) -1, Integer.parseInt(arr[2]));
	  cal.add(Calendar.DATE, -1);

		int year = cal.get(Calendar.YEAR);
		String month = "";
		String day = "";
		if(cal.get(Calendar.MONTH) + 1 < 10) {
			month = "0" + Integer.toString(cal.get(Calendar.MONTH) + 1);
		} else {
			month = Integer.toString(cal.get(Calendar.MONTH) + 1);
		}

		if(cal.get(Calendar.DAY_OF_MONTH) < 10) {
			day = "0" + Integer.toString(cal.get(Calendar.DAY_OF_MONTH));
		} else {
			day = Integer.toString(cal.get(Calendar.DAY_OF_MONTH));
		}
	    
		return year + "-" + month + "-" + day;
	    //return cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1) < 10 ?  + "-" + cal.get(Calendar.DAY_OF_MONTH);
	}
	public static String getTomorrowDate(String date) {
		Calendar cal = new GregorianCalendar();
		String arr[] = date.split("-");
		
		cal.set(Integer.parseInt(arr[0]), Integer.parseInt(arr[1]) -1, Integer.parseInt(arr[2]));
	    cal.add(Calendar.DATE, 1);
	   
		int year = cal.get(Calendar.YEAR);
		String month = "";
		String day = "";
		if(cal.get(Calendar.MONTH) + 1 < 10) {
			month = "0" + Integer.toString(cal.get(Calendar.MONTH) + 1);
		} else {
			month = Integer.toString(cal.get(Calendar.MONTH) + 1);
		}

		if(cal.get(Calendar.DAY_OF_MONTH) < 10) {
			day = "0" + Integer.toString(cal.get(Calendar.DAY_OF_MONTH));
		} else {
			day = Integer.toString(cal.get(Calendar.DAY_OF_MONTH));
		}
	    
		return year + "-" + month + "-" + day;
 
	    //return cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" + cal.get(Calendar.DAY_OF_MONTH);
	}
}
